let initState = {
    navList: [],
    sxList: [],
    index: '',
    SearchData: []
}
function reducer(state = initState, action) {
    state = JSON.parse(JSON.stringify(state))
    if (action.type === 'Home') {
        state.navList = action.payload.data
    }
    if (action.type === "Shaixuan") {
        console.log(action.payload);
        if (action.payload === 0) {
            state.sxList = state.navList
        } else if (action.payload === 1) {
            let arr = state.navList.filter(item => {
                return item.state === "1"
            })
            state.sxList = arr
        } else if (action.payload === 2) {
            let arr = state.navList.filter(item => {
                return item.state === "2"
            })
            state.sxList = arr
        } else if (action.payload === 3) {
            let arr = state.navList.filter(item => {
                return item.state === "3"
            })
            state.sxList = arr
        }
        console.log(state.sxList);
    }
    if (action.type === 'SEARCH') {
        console.log(action.payload);
        state.SearchData = state.navList.filter(item => {
            return item.name.indexOf(action.payload) !== -1
        })
    }
    if (action.type === 'JGSORT') {
        if (action.payload.flag) {
            action.payload.data.sort((a, b) => {
                return b.price - a.price
            })
        } else {
            action.payload.data.sort((a, b) => {
                return a.price - b.price
            })
        }
    }
    if (action.type === 'XLSORT') {
        if (action.payload.flag) {
            action.payload.data.sort((a, b) => {
                return b.peopleNum - a.peopleNum
            })
        } else {
            action.payload.data.sort((a, b) => {
                return a.peopleNum - b.peopleNum
            })
        }
    }
    return state
}
export default reducer